package com.lucky.xyt.core.aop;

import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.github.pagehelper.PageHelper;

@Aspect  
@Component
public class PageAspect {
	@Autowired
	HttpServletRequest request;
	
	@Pointcut("execution(public com.github.pagehelper.PageInfo com.lucky.xyt.modular.*.service.*.*(..))")  
    public void findList(){}  
	
	@Before("findList()")  
    public void deBefore(JoinPoint joinPoint) throws Throwable {
		PageHelper.startPage(this.getPageIndex(), this.getPageSize());
    }
	
	public Integer getPageIndex() {
		return Integer.parseInt(request.getParameter("pageIndex")==null?"1":request.getParameter("pageIndex"));
	}

	public Integer getPageSize() {
		return Integer.parseInt(request.getParameter("pageSize")==null?"10":request.getParameter("pageSize"));
	}
}
